﻿using System;
using System.Collections.Generic;
using System.Data.Entity; // needed for lambda includes
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace TheCup.Controllers
{
    public class CourseController : Controller
    {
        ApiControllers.CourseController cc = new ApiControllers.CourseController();

        public ActionResult Index()
        {
            return View("Index", cc.Get());
        }

        public ActionResult StartsWith(string letter = "A")
        {
            return View("Index", cc.Get(letter));
        }

        public ActionResult Details(int id)
        {
            Course e = cc.Get(id);
            return View(e);
        }

        public ActionResult Create()
        {
            Course e = new Course();
            e.CountryCodeISO3166Alpha2 = "DK";
            return View(e);
        }

        [HttpPost]
        public ActionResult Create(Course e)
        {
            e.uuid = Guid.NewGuid();
            cc.Post(e);

            return RedirectToAction("Index");
        }

        public ActionResult Edit(int id)
        {
            Course e = cc.Get(id);
            return View(e);
        }

        [HttpPost]
        public ActionResult Edit(Course c)
        {
            cc.Put(c.Id, c);
            return RedirectToAction("Details", new { id = c.Id });
        }

    }
}
